package com.alen.sun.dao;

import com.alen.sun.bean.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmployeeMapper {
    @Insert("INSERT INTO employee (employeeId, name, gender, photo, phoneNum, email, password, birthday) " +
            "VALUES (#{employeeId}, #{name}, #{gender}, #{photo}, #{phoneNum}, #{email}, #{password}, #{birthday})")
    void add(Employee employee);

    @Select("select * from employee where employeeId=#{id}")
    Employee getById(String id);

    @Update("update employee set name = #{name},gender = #{gender},photo=#{photo},phoneNum=#{phoneNum}" +
            ",email=#{email},password=#{password},birthday=#{birthday} where employeeId = #{employeeId}")
    Boolean update(Employee employee);

    @Select("SELECT emp.employeeId " +
            "FROM employee emp " +
            "LEFT JOIN (SELECT employeeId, COUNT(*) as count FROM elderly GROUP BY employeeId) eld " +
            "ON emp.employeeId = eld.employeeId " +
            "WHERE eld.count < 4 AND emp.employeeId <> '000000';")
    List<String> getEmployeeId();

    @Select("select * from employee where phoneNum=#{phoneNum} AND password=#{password}")
    Employee selectPhoneNum(Employee employee);

    @Delete("delete from employee where employeeId =#{id}")
    Boolean delete(String id);

    @Select("select * from employee where name like #{word}")
    List<Employee> selectByWord(@Param("word") String word);

    @Select("select * from employee")
    List<Employee> list();

    //批量删除
    @Delete({
            "<script>",
            "delete from employee where employeeId in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    Boolean deleteByIds(List<String> ids);
}
